package com.lottery.system.dao.mapper;

import com.lottery.system.dao.dataobject.ActivityPrizeDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author: xiaoxie
 * create: 2024-09-09 18:58
 * @BelongsProject: lottery-system
 * @BelongsPackage: com.lottery.system.dao.mapper
 * description: 活动奖品表数据层
 */
@Mapper
public interface ActivityPrizeMapper {
    /**
     * @description: 活动奖品列表插入
     * @author: xiaoxie
     * @date: 2024/9/9 19:05
     * @param: [activityPrizeDOList]
     * @return: void
     **/
    @Insert("<script>" +
            " insert into activity_prize (activity_id, prize_id, prize_amount, prize_tiers, status)" +
            " values <foreach collection = 'items' item='item' index='index' separator=','>" +
            " (#{item.activityId}, #{item.prizeId}, #{item.prizeAmount}, #{item.prizeTiers}, #{item.status})" +
            " </foreach>" +
            " </script>")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void batchInsert(@Param("items") List<ActivityPrizeDO> activityPrizeDOList);

    /**
     * @description: 获取活动奖品表信息
     * @author: xiaoxie
     * @date: 2024/9/10 17:23
     * @param: [activityId]
     * @return: java.util.List<com.lottery.system.dao.dataobject.ActivityPrizeDO>
     **/
    @Select(" select id,activity_id,prize_amount,prize_id,prize_tiers,status " +
            " from activity_prize " +
            " where activity_id = #{activityId} ")
    List<ActivityPrizeDO> selectActivityPrizeById(@Param(value = "activityId") Long activityId);

    /**
     * @description: 通过活动id和奖品id(索引) 查询奖品信息
     * @author: xiaoxie
     * @date: 2024/9/11 14:34
     * @param: [activityId, prizeId]
     * @return: com.lottery.system.dao.dataobject.ActivityPrizeDO
     **/
    @Select(" select id,activity_id,prize_amount,prize_id,prize_tiers,status " +
            " from activity_prize " +
            " where activity_id = #{activityId} and prize_id = #{prizeId} ")
    ActivityPrizeDO selectActivityPrizeByIdAndActivityId(@Param(value = "activityId") Long activityId
            , @Param(value = "prizeId") Long prizeId);

    /**
     * @description: 通过活动id和奖品id(索引)更新奖品状态
     * @author: xiaoxie
     * @date: 2024/9/12 21:32
     * @param: [activityId, prizeId, status]
     * @return: void
     **/
    @Update("update activity_prize set status = #{status} " +
            " where activity_id = #{activityId} " +
            " and prize_id = #{prizeId} ")
    void updateStatusByActivityIdAndPrizeId(@Param(value = "activityId") Long activityId
            , @Param(value = "prizeId") Long prizeId
            , @Param(value = "status") String status);

    /**
     * @description: 通过活动id和奖品id(索引)查询状态为INIT的奖品数量
     * @author: xiaoxie
     * @date: 2024/9/12 21:56
     * @param: [activityId, activityId1, name]
     * @return: java.lang.Integer
     **/
    @Select("select count(*) from activity_prize" +
            " where activity_id = #{activityId}" +
            " and status = #{status}")
    Integer activityPrizeCount(@Param(value = "activityId") Long activityId
                             , @Param(value = "status") String status);
}